package cn.stay.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * /amqpTest/sendMsg
 */
@Controller
@RequestMapping("/amqpTest")
public class AmqpTestController {
    @Autowired
    private AmqpTemplate amqpTemplate;

    @RequestMapping("/sendMsg")
    @ResponseBody
    public String sendAmqpMsg(Model model, @RequestParam(value = "msg", defaultValue = "hello world!!!") String msg) {
        if (model != null && !"".equals(msg)) {
            amqpTemplate.convertAndSend("mq.asdfExChange", "mq.asdf.send", msg);
        } else {
            amqpTemplate.convertAndSend("mq.asdfExChange", "mq.asdf.send", "hello world");
        }
        return "success";
    }
}
